﻿using GameFramework;
using GameFramework.Event;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TowerDefence_Zombie
{
    public class UpdateDoubleGlobTimeEventArgs : GameEventArgs
    {
        public static readonly int EventId = typeof(UpdateDoubleGlobTimeEventArgs).GetHashCode();

        public float RemainingTime { get; private set; }

        public string RemainingTimeStr
        {
            get
            {
                return ConvertSecondsToTimeString(RemainingTime);
            }
        }

        public UpdateDoubleGlobTimeEventArgs()
        {
            RemainingTime = 0;
        }

        public override int Id
        {
            get
            {
                return EventId;
            }
        }
        public static UpdateDoubleGlobTimeEventArgs Create(float remainingTime,object userData = null)
        {
            UpdateDoubleGlobTimeEventArgs UpdateDoubleGlobTimeEventArgs = ReferencePool.Acquire<UpdateDoubleGlobTimeEventArgs>();
            UpdateDoubleGlobTimeEventArgs. RemainingTime = remainingTime;
            return UpdateDoubleGlobTimeEventArgs;
        }

        public static string ConvertSecondsToTimeString(float totalSeconds)
        {
            // 确保秒数不为负数
            totalSeconds = Math.Max(0, totalSeconds);

            // 使用TimeSpan处理时间转换
            TimeSpan time = TimeSpan.FromSeconds(totalSeconds);

            // 格式化输出，小时部分不补零，分钟和秒部分补零
            return $"{(int)time.TotalHours}:{time.Minutes:D2}:{time.Seconds:D2}";
        }

        public override void Clear()
        {
            RemainingTime = 0;
        }
    }
}
